package com.view.houseon;

import com.controller.houseon.ControlHouseON;
import com.model.houseon.CasaBean;
import com.presentacion.houseon.R;
import com.presentacion.houseon.R.layout;
import com.presentacion.houseon.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.TextView;

public class InformacionCasaActivity extends Activity {
	
	TextView txt_nombre, txt_puerto, txt_url, txt_ip, txt_paquete, txt_fecha_fin, txt_fecha_ini;
	CheckBox estado;

	ImageButton ibtn_inicio;
	ImageButton ibtn_information;
	ImageButton ibtn_logout;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_informacion_casa);
		
		ibtn_logout=(ImageButton)findViewById(R.id.ibtnEscenarios);
		ibtn_logout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//Toast.makeText(ListaCasaActivity.this, String.valueOf("logout.."), Toast.LENGTH_SHORT).show();
			    AlertDialog.Builder alert = new AlertDialog.Builder(InformacionCasaActivity.this);
                alert.setTitle("Desea Salir?");
                alert.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        salir();
                        }});
                           alert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {  
                               public void onClick(DialogInterface dialog, int whichButton) {    
                            }});
                       alert.show();
			}
		});
		
		ibtn_inicio=(ImageButton)findViewById(R.id.ibtnHome);
		ibtn_inicio.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//Toast.makeText(ListaCasaActivity.this, String.valueOf("perfil.."), Toast.LENGTH_SHORT).show();
				 Intent i = new Intent(InformacionCasaActivity.this, ListaCasaActivity.class);
				 startActivity(i);
			}
		});
		

		ibtn_information=(ImageButton)findViewById(R.id.ibtnInformacion);
		ibtn_information.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//Toast.makeText(ListaCasaActivity.this, String.valueOf("info.."), Toast.LENGTH_SHORT).show();
				 Intent i = new Intent(InformacionCasaActivity.this, InformacionHouseONActivity.class);
				 startActivity(i);
			}
		} );
		
		Bundle b= getIntent().getExtras();
		int idCasa=b.getInt("idCasa");
		
		txt_fecha_fin=(TextView)findViewById(R.id.txtFechaFin_info);
		txt_fecha_ini=(TextView)findViewById(R.id.txtFechaIni_info);
		txt_paquete=(TextView)findViewById(R.id.txt_paquete_info);
		txt_ip=(TextView)findViewById(R.id.txt_ip);
		txt_puerto=(TextView)findViewById(R.id.txt_puerto);
		txt_nombre=(TextView)findViewById(R.id.txt_nombre_casa_info);
		estado=(CheckBox)findViewById(R.id.cb_estado_casa);
		
		CasaBean c= ControlHouseON.getInstancia().BuscarCasaxId(idCasa);
		
		txt_nombre.setText(c.getDescripcion().toString());
		txt_ip.setText(c.getIp().toString());
		txt_puerto.setText(c.getPuerto().toString());
		//txt_url.setText(c.getUrl().toString());
		estado.setChecked(true);
		
		//txt_paquete.setText(c.get.toString());
		//txt_fecha_ini.setText(c.getIp().toString());
		//txt_fecha_fin.setText(c.getIp().toString());
		
	}
	
	   public  void salir(){
	       Intent i = new Intent(); 
	                  i.setAction( Intent.ACTION_MAIN); 
	                  i.addCategory( Intent.CATEGORY_HOME); 
	                  i.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP); 
	                  startActivity(i); 
	                  android.os.Process.killProcess( android.os.Process.myPid()); 
	                  finish();
	  }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.informacion_casa, menu);
		return true;
	}

}
